package com.cn.wanxi.servlet.manage.company;

import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.service.ICompanyService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/companySelectBySome")
public class CompanySelectBySomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");//请求--页面发送给后台时，请求编码格式为utf-8，utf-8是中文格式，gbk也是中文
        resp.setCharacterEncoding("utf-8");//响应--后台发送数据到前台时，编码格式为utf-8
//        1.拿到页面的值
        String phone = req.getParameter("phone");
        String name = req.getParameter("name");
        String net = req.getParameter("net");
        String content = req.getParameter("content");
        String address = req.getParameter("address");
//        2.封装页面拿来的值到model对象
        CompanyModel companyModel = new CompanyModel();
        companyModel.setPhone(phone);
        companyModel.setName(name);
        companyModel.setNet(net);
        companyModel.setContent(content);
        companyModel.setAddress(address);
//        3.调用服务逻辑层
        ICompanyService iCompanyService = new CompanyServiceImpl();
        List<CompanyModel> list = iCompanyService.findBySome(companyModel);
//        4.返回页面数据
        JSONArray jsonArray = JSONArray.fromObject(list);
        resp.getWriter().println(jsonArray);//不会刷新页面
    }
}
